﻿using System;
using System.Text;

/*
 * Write a program that parses an URL address given in the format:
 * [protocol]://[server]/[resource]
 * 
 * [protocol] = "http"
 * [server] = "www.devbg.org"
 * [resource] = "/forum/index.php"
 */

namespace UrlParser
{
    class UrlParser
    {
        struct Url
        {
            public string Protocol, Server, Resource;
        }

        static Url ParseUrl(string urlText)
        {
            int index = 0;
            StringBuilder str = new StringBuilder();
            Url url = new Url();

            //Protocol
            while (urlText[index] != ':')
            {
                str.Append(urlText[index++]);
            }
            url.Protocol = str.ToString();
            str.Clear();
            index += 3;

            //Server
            while (urlText[index] != '/')
            {
                str.Append(urlText[index++]);
            }
            url.Server = str.ToString();
            str.Clear();
            index++;

            //Resource
            str.Append('/');
            while (urlText.Length > index)
            {
                str.Append(urlText[index++]);
            }
            url.Resource = str.ToString();

            return url;
        }

        static void Main(string[] args)
        {
            Url url = ParseUrl("http://www.devbg.org/forum/index.php");

            Console.WriteLine("[protocol] = {0}", url.Protocol);
            Console.WriteLine("[server] = {0}", url.Server);
            Console.WriteLine("[resource] = {0}", url.Resource);
        }
    }
}
